package work.chief.backend.core.generator;

import org.apache.commons.lang3.StringUtils;
import work.chief.backend.domain.Field;

import java.util.ArrayList;
import java.util.List;

/**
 * 递增值 数据生成器
 */
public class IncreaseDataGenerator implements DataGenerator {

    @Override
    public List<String> doGenerate(Field field, int rowNum) {
        String mockParams = field.getMockParams();

        System.out.println("模拟类型: " + mockParams);
        String defaultValue = field.getDefaultValue();


        List<String> list = new ArrayList<>(rowNum);
        if (StringUtils.isBlank(mockParams) || StringUtils.isBlank(defaultValue)) {
            defaultValue = "1";
        }
//        使用默认值作为递增初始值
        int initValue = 0;
        try {
            initValue = Integer.parseInt(defaultValue);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            initValue=1;
        }
        for (int i = 0; i < rowNum; i++) {
            list.add(String.valueOf(initValue + i));
        }
        return list;
    }
}
